<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/6/5
  Time: 8:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="/wechat/order/listPay.css">
    <jsp:include page="../public/head.jsp" flush="true" />
</head>
<body>
<jsp:include page="../public/header.jsp" flush="true" />
<section>
    <div class="my_listpay">
        <form>
            <div class="txt">
                <div class="txt1"><span class="s1">商品数量:</span><span class="s2" id="goodsCount">${paybean.goodsCount}件</span></div>
                <div class="txt2">
                    <span class="s1">商品总价:</span><span class="s2" id="totalPrice">￥${paybean.totalPrice}</span>
                    <span class="s2" style="float:right">￥${paybean.freePrice}</span><span class="s1" style="float:right">优惠:</span>
                </div>
                <div class="txt3">
                    <div class="t-l"><span class="s1">账号余额:</span><span class="s2" id="accountMoney">￥${paybean.accountMoney}</span></div>
                    <div class="t-r"><span class="s1">需支付:</span><span class="s2" id="needPrice">￥${paybean.totalPrice-paybean.freePrice}</span></div>
                </div>
            </div>
            <div class="paybody">
                <div class="tit">请选择下列的付款方式:</div>
                <form id="form">
                <div class="cont">
                    <input name="paytype" type="radio" class="mycash" value="1" ><i class="iconfont icon2" id="i1">&#xe61c;</i>
                    <i class="iconfont icon1">&#xe623;</i><span>余额支付</span>
                </div>
                <%--<div class="cont">--%>
                    <%--<input name="paytype" type="radio" class="mybank" onclick="cg('i2')" value="2"><i class="iconfont icon2" id="i2">&#xe61c;</i>--%>
                    <%--<i class="iconfont icon1 bank">&#xe62b;</i><span>支付宝</span>--%>
                <%--</div>--%>
                <div class="cont last">
                    <input name="paytype" type="radio" class="myweixin"  value="3"><i class="iconfont icon2" id="i3">&#xe61c;</i>
                    <i class="iconfont icon1 weixin">&#xe61a;</i><span>微信支付</span>
                </div>
                </form>
            </div>
            <input type="button" name="" class="btnComplain" value="去付款" onclick="dopay()">
        </form>
    </div>
    <!--/my_listpay END-->
</section>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js" type="text/javascript"></script>
<script>
    var orderNo;
    var wxappId = '${paybean.weiPay.appId}';
    var wxtimeStamp = '${paybean.weiPay.timeStamp}';
    var nonceStr = '${paybean.weiPay.nonceStr}';
    var prepay_id = '${paybean.weiPay.prepayId}';
    var wxpaySign = '${paybean.weiPay.paySign}';

    function dopay() {
        var witch = $("input[name='paytype']:checked").val();
        if (!confirm("是否支付？")){
            return;
        }
        tip("","正在请求支付",false);
        $("")
        switch (witch){
            case '1':
                ye_pay();
                break;
            case '2':
                alert("支付宝支付");
                break;
            case '3':
                wechat_pay();
                break;
        }
    }

    function ye_pay() {

        $.get("/mobile/user/order?action=pay&orderNo=${orderNo}",function (data) {
            if (!data.success){
                alert(data.msg);
            }else {
                window.location.replace("/order/orderList.do");
            }
        },"json");
    }

    function ali_pay() {
        window.location.href = 'https://mapi.alipay.com/gateway.do?${paybean.alipay}';
    }

    function wechat_pay() {
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        }else{
            onBridgeReady();
        }
    }
    function onBridgeReady(){

        WeixinJSBridge.invoke(
                'getBrandWCPayRequest', {
                "appId": wxappId,     //公众号名称，由商户传入
                "timeStamp":wxtimeStamp,         //时间戳，自1970年以来的秒数
                "nonceStr": nonceStr, //随机串
                "package": "prepay_id="+prepay_id,
                "signType": "MD5",         //微信签名方式：
                "paySign": '${paybean.weiPay.paySign}' //微信签名
    },
        function(res){
            if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                window.location.replace("/order/orderList.do");
            }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
        }
    );
    }


</script>
</body>
</html>
